package org.sabayframework.cluster;

import java.math.BigDecimal;

import org.sabayframework.activity.ActivityContext;
import org.sabayframework.activity.impl.StatefulActivity;
import org.sabayframework.channel.Lock;


public class Sum extends StatefulActivity<String, String> {

	private String result;
	
	@Override
	public int getInputSize(ActivityContext<String, String> ctx) {
		return 2;
	}

	@Override
	public void input(ActivityContext<String, String> ctx, Lock<String> inputLock) {
		BigDecimal op1 = new BigDecimal(inputLock.get(0));
		BigDecimal op2 = new BigDecimal(inputLock.get(1));
		result = op1.add(op2).toString();
	}

	@Override
	public void output(ActivityContext<String, String> ctx, Lock<String> outputLock) {
		outputLock.set(0, result);
	}

}
